<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:th="http://www.thymeleaf.org">

<head th:replace="component/head :: head"></head>

<body>
	<header th:replace="component/header :: header"></header>

	<!-- Begin page content -->
	<div class="container">
		<div class="row">
			<div th:replace="component/sidebar"></div>

			<div class="col-md-9">
				<div th:replace="component/page-title::pageTitle('图书元数据')"></div>
				<div class="row">
					<div class="col-md-4">
						<div class="dropdown">
							<div class="input-group">
								<div class="input-group-prepend">
									<label class="input-group-text" for="name">请输入书名：</label>
								</div>
								<input type="text" class="form-control" id="name"
									aria-describedby="basic-addon3">
								<button type="button" class="btn btn-primary"
									onclick="selectBooks()">查询</button>
							</div>
						</div>
					</div>
				</div>

				<!-- 列表 -->
				<div class="row mt-3">
					<div class="col-md-12">
						<table id="listTable" class="table table-striped">
							<thead>
								<tr>
									<th scope="col">编号</th>
									<th scope="col">书名</th>
									<th scope="col">书编</th>
									<th scope="col">作者</th>
									<th scope="col">详情</th>
								</tr>
							</thead>
							<tbody>
								<!-- 动态追加tr -->
							</tbody>
						</table>
					</div>
				</div>

			</div>
		</div>
	</div>

	<footer th:replace="component/footer :: footer"></footer>

	<div th:replace="component/footer-lib"></div>
	<script type="text/javascript">
		function selectBooks() {
			var name = $('#name').val();
			if (name == "") {
				alert("请输入需要借阅的书名！");
				return;
			}
			$
					.ajax({
						url : "/restmetadata/get-bookandurlvos-by-name",
						type : "POST",
						contentType : "application/json; charset=utf-8",
						data : name,
						dataType : 'json',
						async : true,
						success : function(result) {
							if (result.success == false) {
								if (result.code == 9002) {
									alert("参数错误");
								} else if (result.code == 9999) {
									alert("系统错误");
								}
							} else {
								//bookAndUrlVO集
								var list = result.module;
								//清空table
								$("#listTable tbody").empty();
								//渲染table
								if (list.length <= 0) {
									alert("系统中查无此图书！");
									location.reload();
								}
								for (var i = 0; i < list.length; i++) {
									var id = list[i].id;
									var bookName = list[i].bookVO.name;
									var number = list[i].bookVO.number;
									var author = list[i].bookVO.author;
									var url = list[i].url;
									$("#listTable tbody")
											.append(
													"<tr><th scope=\"row\">"
															+ (i + 1)
															+ "</th><td>"
															+ bookName
															+ "</td><td>"
															+ number
															+ "</td><td>"
															+ author
															+ "</td><td><a href="+url+">详情</a></td></tr>");
								}
							}
						},
						error : function(e) {
							alert("异常");
						}
					});
		}
	</script>

</body>

</html>